<template>
  <div id="admin-manage" class="page-wrapper">
    <div class="selector-wrapper main-card wrapper">
      <div class="main-card">
        <GroupSelector :selectorData="selectorData" />
      </div>
      <el-button type="primary" @click="handleSubmitClick">获取数据</el-button>
    </div>
    <div class="wrapper main-card">
      <el-table
        ref="singleTable"
        :data="tableData"
        highlight-current-row
        @current-change="handleCurrentChange"
        style="width: 100%"
      >
        <el-table-column
          property="meterNumber"
          label="电表编号"
          width="120"
        ></el-table-column>
        <el-table-column
          property="meterRead"
          label="电表读数(度)"
        ></el-table-column>
        <el-table-column
          property="lastRead"
          label="上次电表读数(度)"
        ></el-table-column>
        <el-table-column label="电器状态">
          <template slot-scope="scope">
            <el-switch
              v-model="scope.row.value"
              active-color="#13ce66"
              inactive-color="#ff4949"
              active-value="1"
              inactive-value="0"
              @change="handleSwitchChange(scope.row)"
            >
            </el-switch>
          </template>
        </el-table-column>
        <el-table-column property="power" label="使用功率"></el-table-column>
        <el-table-column property="date" label="用表日期"></el-table-column>
        <!-- <el-table-column property="meterNumber" label="电表编号"></el-table-column> -->
        <el-table-column
          property="master_id"
          label="主控编号"
        ></el-table-column>
        <el-table-column
          property="limitPower"
          label="限制功率"
        ></el-table-column>
      </el-table>
    </div>
  </div>
</template>

<script>
import GroupSelector from '@/components/GroupSelector'
export default {
  name: 'RoomInfo',
  components: {
    GroupSelector
  },
  data() {
    return {
      selectorData: {
        buildingId: null,
        floorId: null,
        roomId: null
      },
      tableData: [
        {
          value: '0',
          number: '001001',
          name: '学生',
          totalMoney: '2000',
          depositMoney: '500',
          subsidyMoney: '50',
          meterRead: '5002',
          lastRead: '4500',
          state: '0',
          power: '200',
          date: '2024-03-30',
          meterNumber: '010101',
          master_id: '01',
          control: '0101',
          limitPower: '300'
        },
        {
          value: '1',
          number: '001002',
          totalMoney: '2000',
          depositMoney: '500',
          subsidyMoney: '50',
          meterRead: '5002',
          lastRead: '4500',
          state: '0',
          power: '200',
          date: '2024-03-30',
          meterNumber: '010102',
          master_id: '01',
          control: '0101',
          limitPower: '300'
        },
        {
          value: '1',
          number: '001003',
          totalMoney: '2000',
          depositMoney: '500',
          subsidyMoney: '50',
          meterRead: '5002',
          lastRead: '4500',
          state: '0',
          power: '200',
          date: '2024-03-30',
          meterNumber: '010103',
          master_id: '01',
          control: '0101',
          limitPower: '300'
        },
        {
          value: '1',
          number: '001004',
          totalMoney: '2000',
          depositMoney: '500',
          subsidyMoney: '50',
          meterRead: '5002',
          lastRead: '4500',
          state: '0',
          power: '200',
          date: '2024-03-30',
          meterNumber: '010104',
          master_id: '01',
          control: '0101',
          limitPower: '300'
        }
      ],
      currentRow: null
    }
  },

  methods: {
    handleSwitchChange(row) {
      if (row.value === '1') {
        this.$message.success('开关已打开')
      } else {
        this.$message.warning('开关已关闭')
      }
    }
  }
}
</script>
<style lang="scss" scoped>
.wrapper {
  margin: 40px 0;
}

.selector-wrapper {
  display: flex;
  justify-content: space-between;
  align-items: center; /* 垂直居中 */
}

.list-wrapper {
  margin-top: 40px;
}
.el-form-item--small.el-form-item {
  margin-bottom: 0px;
}
.form-item-wrapper {
  display: flex;
  justify-content: space-between;
}
</style>
